#include "SrpcApplication.h"
#include "SrpcLogger.h"
#include <glog/logging.h>

SrpcConfig SrpcApplication::m_config;

void SrpcApplication::Init(int argc, char **argv) {
  if (argc < 2) {
    SrpcLogger::ERROR("usage: command -i <config file path>");
    exit(EXIT_FAILURE);
  }
  int o;
  std::string config_file;
  // 使用getopt解析命令行参数
  while ((o = getopt(argc, argv, "i:")) != -1) {
    switch (o) {
    case 'i':
      config_file = optarg;
      break;
    case '?':
      SrpcLogger::ERROR("usage: command -i <config file path>");
      exit(EXIT_FAILURE);
      break;
    case ':':
      SrpcLogger::ERROR("usage: command -i <config file path>");
      exit(EXIT_FAILURE);
      break;
    default:
      break;
    }
  }
  m_config.LoadConfigFile(config_file.c_str());
}

SrpcApplication &SrpcApplication::GetInstance() {
  static SrpcApplication application;
  return application;
}

SrpcConfig &SrpcApplication::GetConfig() { return m_config; }

SrpcApplication::SrpcApplication() {}

SrpcApplication ::~SrpcApplication() {}